<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/22
 * Time: 12:52
 */

namespace Admin\Controller;

class BookManageController extends BaseController
{
    //    /**
    //     * session存储book_id
    //     **/
    //    public function sessionBookId(){
    //        $book_id=I('book_id');
    //        session('book_id',$book_id);
    //    }
    //    /**
    //     * 清    空sessionId
    //    **/
    //    public function sessionNullBookId(){
    //        session('book_id',null);
    //    }
    /**
     * 书籍展示
    **/
    public function bookShow()
    {
        //        $book_id=getBookId();
        //        if(!empty($book_id)){
        //            $getBookByIdInfo=D('BookManage')->getBookByIdInfo($book_id);
        //            $this->assign('_getBookByIdInfo',$getBookByIdInfo);
        //        }
        $book_name=I('book_name');
        $book_type_id=I('book_type_id');
        $book_case_id=I('book_case_id');
        $book_isbn_id=I('book_isbn_id');
        $getBookShowInfo=D('BookManage')->getBookShowInfo($book_name, $book_type_id, $book_case_id, $book_isbn_id);
        $getBookTypeTableInfo=D('BookType')->getBookTypeTableInfo();
        $getBookIsbnTableInfo=D('BookIsbn')->getBookIsbnTableInfo();
        $getBookCaseTableInfo=D('BookCase')->getBookCaseTableInfo();
        $this->assign('_getBookShowInfo', $getBookShowInfo);
        $this->assign('_getBookCaseTableInfo', $getBookCaseTableInfo);
        $this->assign('_getBookIsbnTableInfo', $getBookIsbnTableInfo);
        $this->assign('_getBookTypeTableInfo', $getBookTypeTableInfo);
        $this->display('BookManage/bookShow');
    }
    /**
     * 书籍录入
     **/
    public function bookEntering()
    {
        $getBookTypeTableInfo=D('BookType')->getBookTypeTableInfo();
        $getBookIsbnTableInfo=D('BookIsbn')->getBookIsbnTableInfo();
        $getBookCaseTableInfo=D('BookCase')->getBookCaseTableInfo();
        $this->assign('_getBookCaseTableInfo', $getBookCaseTableInfo);
        $this->assign('_getBookIsbnTableInfo', $getBookIsbnTableInfo);
        $this->assign('_getBookTypeTableInfo', $getBookTypeTableInfo);
        $this->display('BookManage/bookEntering');
    }
    /**
     * 论坛管理
     **/
    public function forumManage()
    {
        $feel_title=I('feel_title');
        $feel_del=I('feel_del');
        $getForumInfo=D('ForumManage')->getForumInfo($feel_title, $feel_del);
        $this->assign('_getForumInfo', $getForumInfo);
        $this->display('BookManage/forumManage');
    }
    /**
     * 标题禁用
    **/
    public function forumDel()
    {
        $feel_id=I('feel_id');
        $res=D('ForumManage')->forumDel($feel_id);
        if ($res==false) {
            $this->error('禁用失败', null, true);
        } else {
            $this->success('禁用成功', null, true);
        }
    }
    /**
     * 标题恢复
     **/
    public function forumRec()
    {
        $feel_id=I('feel_id');
        $res=D('ForumManage')->forumRec($feel_id);
        if ($res==false) {
            $this->error('恢复失败', null, true);
        } else {
            $this->success('恢复成功', null, true);
        }
    }
    /**
     * 论坛详情
    **/
    public function forumInfo()
    {
        $feel_id=I('feel_id');
        $getAllUserInfo=D('User')->getAllUserInfo();
        $getByIdForumInfo=D('ForumManage')->getByIdForumInfo($feel_id);
        $this->assign('_getAllUserInfo', $getAllUserInfo);
        $this->assign('_getByIdForumInfo', $getByIdForumInfo);
        $this->display('BookManage/forumInfo');
    }
    /**
     * 广播管理
     **/
    public function radioManage()
    {
        $this->display('BookManage/radioManage');
    }

    /**
     * 书籍添加
    **/
    public function bookEnterAdd()
    {
        $a_id=getAdminId();
        $book_name=I('book_name');
        $book_barcode=I('book_barcode');
        $book_type_id=I('book_type_id');
        $book_isbn_id=I('book_isbn_id');
        $book_case_id=I('book_case_id');
        $book_author=I('book_author');
        $book_translator=I('book_translator');
        $book_price=I('book_price');
        $book_number=I('book_number');
        if (empty($a_id)||empty($book_name)||empty($book_author)||empty($book_price)||empty($book_number)||empty($book_barcode)) {
            $this->error('标准信息不能为空！');
        }
        $bookName=D('BookManage')->getBookName(null, $book_name);
        if ($bookName==true) {
            $this->error('书籍名称已存在，请重新录入！');
        }
        $res=D('BookManage')->bookInfoAdd($a_id, $book_name, $book_barcode, $book_type_id, $book_isbn_id, $book_case_id, $book_author, $book_translator, $book_price, $book_number);
        if ($res==false) {
            $this->error('添加失败！');
        } else {
            $this->success('添加成功！', U('Admin/BookManage/bookEntering'));
        }
    }
    /**
     * 书籍修改跳转
     **/
    public function bookShowSaveTiao()
    {
        $book_id=I('book_id');
        session('book_id', $book_id);
        if (empty($book_id)) {
            $book_id=getBookId();
        }
        $getAdminAllInfo=D('AdminLogin')->getAdminAllInfo();
        $getBookTypeTableInfo=D('BookType')->getBookTypeTableInfo();
        $getBookIsbnTableInfo=D('BookIsbn')->getBookIsbnTableInfo();
        $getBookCaseTableInfo=D('BookCase')->getBookCaseTableInfo();
        $this->assign('_getAdminAllInfo', $getAdminAllInfo);
        $this->assign('_getBookCaseTableInfo', $getBookCaseTableInfo);
        $this->assign('_getBookIsbnTableInfo', $getBookIsbnTableInfo);
        $this->assign('_getBookTypeTableInfo', $getBookTypeTableInfo);
        $getBookSaveInfo=D('BookManage')->getBookSaveInfo($book_id);
        $this->assign('_getBookSaveInfo', $getBookSaveInfo);
        $this->display('BookManage/bookSave');
    }
    /**
     * 书籍修改
    **/
    public function bookShowSave()
    {
        $book_id=getBookId();
        $book_name=I('book_name');
        $book_type_id=I('book_type_id');
        $book_isbn_id=I('book_isbn_id');
        $book_case_id=I('book_case_id');
        $book_author=I('book_author');
        $book_translator=I('book_translator');
        $book_price=I('book_price');
        $book_number=I('book_number');
        if (empty($book_name)||empty($book_type_id)||empty($book_isbn_id)||empty($book_case_id)||empty($book_author)||empty($book_price)||empty($book_number)) {
            $this->error('信息不能为空');
        }
        $res=D('BookManage')->bookShowSave($book_id, $book_name, $book_type_id, $book_isbn_id, $book_case_id, $book_author, $book_translator, $book_price, $book_number);
        if ($res==false) {
            $this->error('修改失败');
        } else {
            $this->success('修改成功', U('Admin/BookManage/bookShowSaveTiao'));
        }
    }
    /**
     * 书籍名称校验
    **/
    public function getBookNamecheck()
    {
        $book_id=I('book_id');
        $book_name=I('book_name');
        if (empty($book_name)) {
            $this->error('不能为空', null, true);
        }
        if (!empty($book_id)) {
            $res=D('BookManage')->getBookName($book_id, $book_name);
            if ($res==false) {
                $this->success('可以使用', null, true);
            } else {
                $this->error('不可使用', null, true);
            }
        } else {
            $res=D('BookManage')->getBookName(null, $book_name);
            if ($res==false) {
                $this->success('可以使用', null, true);
            } else {
                $this->error('不可使用', null, true);
            }
        }
    }
    /**
     * 书籍禁用
    **/
    public function bookShowDel()
    {
        $book_id=I('book_id');
        $res=D('BookManage')->bookShowDel($book_id);
        if ($res==false) {
            $this->error('下架失败', null, true);
        } else {
            $this->success('下架成功', null, true);
        }
    }
    /**
     * 书籍恢复
     **/
    public function bookShowRec()
    {
        $book_id=I('book_id');
        $res=D('BookManage')->bookShowRec($book_id);
        if ($res==false) {
            $this->error('上架失败', null, true);
        } else {
            $this->success('上架成功', null, true);
        }
    }
}
